

target("com")
    set_kind("static")
    add_files("ringbuffer.c")
    add_files("ringbuffer_ext.c")
    add_files("usbpack.c")
    add_files("socketfd_port.c")
    add_files("timspec_helper.c")
    add_files("ioctl_tab.c")
    add_files("com_log.c")
    add_files("bg_proc.c")

    add_includedirs("./" , {public=true})
    add_headerfiles("bb_api.h")
    add_headerfiles("bb_config.h")
    add_headerfiles("ar_net_api.h")
    on_load(function (target)
        local ardir = path.join(os.scriptdir(),"../../../")

        if os.isfile(path.join(os.scriptdir(), "bb_api.h")) == false then
            os.trycp(path.join(ardir , "release/inc/bb_api.h") , os.scriptdir())
        end

        if os.isfile(path.join(os.scriptdir(), "ar_net_api.h")) == false then
            os.trycp(path.join(ardir , "release/inc/ar_net_api.h") , os.scriptdir())
        end

        if os.isfile(path.join(os.scriptdir(), "ioctl_tab.c")) == false then
            os.trycp(path.join(ardir , "../arsdk/platforms/baseband/bb_rpc/ioctl_tab.c") , os.scriptdir())
        end

        if os.isfile(path.join(os.scriptdir(), "ioctl_tab.h")) == false then
            os.trycp(path.join(ardir , "../arsdk/platforms/baseband/bb_rpc/ioctl_tab.h") , os.scriptdir())
        end

        if os.isfile(path.join(os.scriptdir(), "bb_config.h")) == false then
            for _,conpath in ipairs(
                    {
                        "release/inc/bb_config.h",
                        "../arsdk/platforms/baseband/bb_core/api/bb_config.h",
                        "../arsdk/platforms/baseband/bb_core/api/configs/bb_config.h",
                    }
                )do
                if os.isfile(path.join(ardir,conpath)) then
                    os.cp(path.join(ardir,conpath) , os.scriptdir())
                    break
                end
            end
        end
    end)

    if get_config('target_os') == "linux" or is_plat("linux") then
        add_cxflags("-fPIC")
    elseif is_plat("windows") then
        add_files("CrashDump.cpp")
        add_files(path.join("getopt","getopt.c") , {cflags = "-DHAVE_STRING_H=1"})
        add_files(path.join("getopt","getopt1.c"))
        add_includedirs("getopt" , {public=true})
    end
